/**
 * Copyright 1999-2015 dangdang.com.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package spring.cloud.tasks.api.utils;

public final class TaskNodePath {

    public static final String $TASKS_NODE_NAME = "$tasks";

    private TaskNodePath() {
    }

    public static String getReportPath(String jobName) {
        return String.format("/%s/%s/control/report", $TASKS_NODE_NAME, jobName);
    }

    public static String getAnalyseResetPath(String jobName) {
        return String.format("/%s/%s/analyse/reset", $TASKS_NODE_NAME, jobName);
    }

    public static String getProcessCountPath(String jobName) {
        return String.format("/%s/%s/analyse/processCount", $TASKS_NODE_NAME, jobName);
    }

    public static String getErrorCountPath(String jobName) {
        return String.format("/%s/%s/analyse/errorCount", $TASKS_NODE_NAME, jobName);
    }

    public static String getTasksNodePath() {
        return "/" + $TASKS_NODE_NAME;
    }

    public static String getTaskNodePath(String jobName) {
        return String.format("/%s/%s", $TASKS_NODE_NAME, jobName);
    }

    public static String getConfigNodePath(final String jobName) {
        return String.format("/%s/%s/config", $TASKS_NODE_NAME, jobName);
    }

    public static String getConfigNodePath(final String jobName, final String nodeName) {
        return String.format("/%s/%s/config/%s", $TASKS_NODE_NAME, jobName, nodeName);
    }

    public static String getExecutorsNodePath(final String jobName) {
        return String.format("/%s/%s/executor", $TASKS_NODE_NAME, jobName);
    }

    public static String getExecutorsNodePath(final String jobName, final String executorName) {
        return String.format("/%s/%s/servers/%s", $TASKS_NODE_NAME, jobName, executorName);
    }

    public static String getExecutorsNodePath(final String jobName, final String executorName, final String nodeName) {
        return String.format("%s/%s/%s", getExecutorsNodePath(jobName), executorName, nodeName);
    }

    public static String getExecutionNodePath(final String jobName) {
        return String.format("/%s/%s/execution", $TASKS_NODE_NAME, jobName);
    }

    public static String getExecutionItemNodePath(final String jobName, final String item) {
        return String.format("/%s/%s/execution/%s", $TASKS_NODE_NAME, jobName, item);
    }

    public static String getExecutionNodePath(final String jobName, final String item, final String nodeName) {
        return String.format("%s/%s/%s", getExecutionNodePath(jobName), item, nodeName);
    }

    public static String getLeaderNodePath(final String jobName, final String nodeName) {
        return String.format("/%s/%s/leader/%s", $TASKS_NODE_NAME, jobName, nodeName);
    }

    public static String getRunOneTimePath(final String jobName, final String executorName) {
        return String.format("/%s/%s/servers/%s/runOneTime", $TASKS_NODE_NAME, jobName, executorName);
    }

    public static String getStopOneTimePath(final String jobName, final String executorName) {
        return String.format("/%s/%s/servers/%s/stopOneTime", $TASKS_NODE_NAME, jobName, executorName);
    }

    public static String getExecutorStatus(final String jobName, final String executorName) {
        return String.format("/%s/%s/servers/%s/status", $TASKS_NODE_NAME, jobName, executorName);
    }

    public static String getServerStoppedFlag(final String jobName, final String executorName) {
        return String.format("/%s/%s/servers/%s/stoped", $TASKS_NODE_NAME, jobName, executorName);
    }

    public static String getProcessSucessCount(final String jobName, final String executorName) {
        return String.format("/%s/%s/servers/%s/processSuccessCount", $TASKS_NODE_NAME, jobName, executorName);
    }

    public static String getProcessFailureCount(final String jobName, final String executorName) {
        return String.format("/%s/%s/servers/%s/processFailureCount", $TASKS_NODE_NAME, jobName, executorName);
    }

    public static String getServerSharding(final String jobName, final String executorName) {
        return String.format("/%s/%s/servers/%s/sharding", $TASKS_NODE_NAME, jobName, executorName);
    }

    public static String getFailoverNodePath(final String jobName, final String item) {
        return TaskNodePath.getExecutionNodePath(jobName, item, "failover");
    }

    public static String getRunningNodePath(final String jobName, final String item) {
        return TaskNodePath.getExecutionNodePath(jobName, item, "running");
    }

    public static String getCompletedNodePath(final String jobName, final String item) {
        return TaskNodePath.getExecutionNodePath(jobName, item, "completed");
    }

    public static String getFailedNodePath(final String jobName, final String item) {
        return TaskNodePath.getExecutionNodePath(jobName, item, "failed");
    }

    public static String getTimeoutNodePath(final String jobName, final String item) {
        return TaskNodePath.getExecutionNodePath(jobName, item, "timeout");
    }

    public static String getEnabledReportNodePath(final String jobName) {
        return TaskNodePath.getConfigNodePath(jobName, "enabledReport");
    }

    public static String getLeaderFailoverNodePath(final String jobName) {
        return TaskNodePath.getLeaderNodePath(jobName, "failover");
    }

    public static String getLeaderFailoverItemPath(final String jobName, final String item) {
        return String.format("%s/items/%s", getLeaderFailoverNodePath(jobName), item);
    }

}
